package com.zxt.content.user.service.impl;

import com.zxt.content.common.utils.ZXTBeanUtils;
import com.zxt.content.common.utils.ZXTCollectionsUtil;
import com.zxt.content.user.enums.EventTypeEnum;
import com.zxt.content.user.manager.LifeLogManager;
import com.zxt.content.user.model.LifeLog;
import com.zxt.content.user.req.LifeLogDTO;
import com.zxt.content.user.resp.LifeLogVO;
import com.zxt.content.user.service.LifeLogService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 生活日志模块业务逻辑层
 *
 * @author zxt
 */
@Service(value = "lifeLogService")
@AllArgsConstructor
public class LifeLogServiceImpl implements LifeLogService {

    private final LifeLogManager lifeLogManager;

    @Override
    public List<LifeLogVO> list() {
        List<LifeLogVO> vos = ZXTBeanUtils.beanCopy(lifeLogManager.list(), LifeLogVO.class);
        if (ZXTCollectionsUtil.isEmpty(vos)) {
            return new ArrayList<>();
        }

        for (LifeLogVO vo : vos) {
            vo.setEventTypeDesc(EventTypeEnum.getDescByValue(vo.getEventType()));
        }

        return vos;
    }

    @Override
    public void add(LifeLogDTO dto) {
        lifeLogManager.save(ZXTBeanUtils.beanCopy(dto, LifeLog.class));
    }
}
